from google.appengine.ext import webapp
from google.appengine.api import users
from entities import *
from Entities import *

def Add(languageName):
    language = db.GqlQuery("SELECT * FROM Language WHERE LanguageName =:1",languageName)
    if language.count() == 0:
        language = Language(LanguageName = languageName)
        language.put()
        return 1
    else:
        return 0
    
def Delete(languageName):
    language = db.GqlQuery("SELECT * FROM Language WHERE LanguageName =:1",languageName)
    if language.count() == 0:
        return 0
    else:
        Language.delete(language)
        return 1
        
def Get():
    language_list = []
    languages = db.GqlQuery("SELECT * FROM Language ORDER BY LanguageName DESC")
    for language in languages:
        language_dict = {}
        language_dict["LanguageName"] = language.LanguageName
        language_dict["LanguageID"] = language.key().id()
        language_list.append(language_dict)
    tuple_language = tuple(language_list)
    return tuple_language